/**
 * Copyright (C), 2020, 安徽贝慕信息科技有限公司
 * FileName: DealerCompanyControllerImpl
 * Author:   Allen
 * Date:     2020/8/27 17:28
 * Description: 商家基本信息登记处理实现类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bim.marvel.rest.impl;

import com.bim.marvel.openapi.client.dto.DealerCompanyDTO;
import com.bim.marvel.openapi.client.query.DealerCompanyQuery;
import com.bim.marvel.common.core.constant.CodeEnum;
import com.bim.marvel.common.core.model.dto.SimpleVO;
import com.bim.marvel.openapi.core.entity.DealerCompanyDO;
import com.bim.marvel.openapi.core.service.impl.DealerCompanyService;
import com.bim.marvel.rest.DealerCompanyController;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;

/**
 * 〈商家基本信息登记处理实现类〉
 *
 * @author Allen
 * @date 2020/8/27
 * @since 1.0.0
 */
@RestController
public class DealerCompanyControllerImpl implements DealerCompanyController {

    /**
     * 注入DealerCompanyService
     */
    @Autowired
    private DealerCompanyService dealerCompanyService;

    @Override
    public SimpleVO<String> saveDealerCompany(DealerCompanyQuery dealerCompanyQuery) {
        String companyCode = dealerCompanyService.saveDealerCompany(dealerCompanyQuery);
        if (StringUtils.isEmpty(companyCode)) {
            return new SimpleVO(CodeEnum.INSERT_FAILED);
        }
        return new SimpleVO<>(companyCode);
    }

    @Override
    public SimpleVO<DealerCompanyDTO> getDealerCompany(String companyId) {
        DealerCompanyDO dealerCompanyDO = dealerCompanyService.getById(companyId);
        if (dealerCompanyDO == null) {
            return new SimpleVO(CodeEnum.DATA_NOT_FOUND);
        }
        DealerCompanyDTO dealerCompanyDTO = new DealerCompanyDTO();
        BeanUtils.copyProperties(dealerCompanyDO, dealerCompanyDTO);
        return new SimpleVO<>(dealerCompanyDTO);
    }
}
